#ifndef _SERIAL_H
#define _SERIAL_H
#include <list>
#include <iostream>
#include "windows.h"
//#include "data_Provider.h"


using namespace std;

#define MAX_NUM_SERIAL 10

class CMySerial
{
private:
	CString currentComName;
	HANDLE hCom;
	DCB m_serialConfig;
	const UINT_PTR serialSendTimerId = 10;
public:
	list <CString> comNameList;
	int Serial_open();
	int Serial_read(void *OutBuf, DWORD size);
	int Serial_write(const void *Buf, int size);
	void Serial_close(void);
	int Serial_scan(void);

	void Serial_SetCurrentComPort(CString comPortName);
	CString Serial_GetCurrentComPort(void);

	void Serial_SetSerialConfig(DCB * pstSerialConfig);

	HANDLE Serial_GetHandle(void);

	//int startSendTimer(void);

	//int stopSendTimer(void);

	//CDataProvider * m_pCDataProvider;

	CMySerial();

	virtual ~CMySerial();
};




typedef enum 
{
	NAME_EMPTY = 1,
	OPEN_FAILED,
	GET_STATUS_FAILED,
	SET_STATUS_FAILED,
	PURGE_FAILED

}enErrorCode;

extern char * errorMsg[];

CString errorCodeToString(enErrorCode codeIn);


VOID CALLBACK serialSendTimerProc(PVOID lpParam, BOOLEAN TimerOrWaitFired);

extern HANDLE hSerialSendTimer;
extern HANDLE hTimerQueue;

typedef enum
{
	NOT_RUN,
	RUNNING,
	STOPPING,
	STOP_FINISHED
}ThreadRunFlag;

UINT ReadComPortThreadFunc(LPVOID pParm);


#endif